<template>
  <div class="docs-view">
    <img class="toggle-catalog" @click="toggleCatalog" src="./catalog.svg">
    <div class="nav-list-wrapper">
      <side-list :nav-list="navList"></side-list>
    </div>
    <div v-show="showCatalog" class="mask" @click="toggleCatalog"></div>
    <router-view class="page-doc md-body" v-highlight></router-view>
    <display></display>
  </div>
</template>

<script>
import SideList from '../side-list/side-list.vue'
import Display from '../display/display.vue'
import menuConfig from '../../common/config/menu'

export default {
  data() {
    return {
      navList: menuConfig,
      showCatalog: true
    }
  },
  watch: {
    $route() {
      this.showCatalog = false
      window.scrollTo(0, 0)
    }
  },
  mounted() {
    console.log('navList', this.navList)
  },
  methods: {
    toggleCatalog() {
      this.showCatalog = !this.showCatalog
    }
  },
  components: {
    SideList,
    Display
  }
}
</script>

<style lang="scss" >
@import '~assets/stylesheets/main';
.docs-view {
  display: flex;
  width: 100%;
  height: 100%;
  flex-wrap: wrap;
  overflow: hidden;
  @media screen and (max-width: 960px) {
    position: relative;
    height: auto;
  }
  .toggle-catalog {
    display: none;

    @media screen and (max-width: 960px) {
      display: block;
      position: absolute;
      right: 20px;
      top: 20px;
      width: 20px;
      height: 20px;
      padding: 10px;
      background-color: white;
      box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    &:active {
      opacity: 0.6;
    }
  }

  .nav-list-wrapper {
    height: 100%;

    @media screen and (max-width: 960px) {
      position: absolute;
      right: 0;
      top: 0;
      background-color: white;
      z-index: 1;
      overflow: hidden;
      transform: translate(100%, 0);
      transition: all 0.4s ease;

      &.active {
        transform: translate(0, 0);
      }
    }
  }

  .mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;

    &.active {
      background-color: rgba(0, 0, 0, 0.2);
      transition: all 0.4s ease;
    }
  }
}
.page-sidelist {
  flex: none;
  width: 190px;
  height: 100%;
  padding: 40px 20px;
  box-sizing: border-box;
  overflow-y: auto;

  @media screen and (max-width: 960px) {
    height: 100%;
    padding: 5px 20px;
  }
}

.page-doc {
  flex: 1;
  height: 100%;
  padding: 44px 20px 20px 20px;
  box-sizing: border-box;
  overflow-y: auto;

  @media screen and (max-width: 960px) {
    flex: 1 1 100%;
    height: auto;
    padding: 20px 20px 0 20px;
  }

  h2:first-child {
    margin-top: 0;
  }
}

.page-display {
  flex: none;
  width: 420px;
  overflow-y: auto;

  @media screen and (max-width: 960px) {
    flex: 1 1 100%;
    height: 800px;
  }
}
.md-body {
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  p {
    margin: 1.2em 0;
    .anchor {
      display: inline-block;
    }
  }
  h2 {
    margin-top: 1.2em;
    margin-bottom: 0.8em;
    font-size: 1.5em;
    font-weight: 600;
  }
  h3 {
    margin: 1em 0 1em;
    font-size: 1.25em;
    font-weight: 600;
  }
  h4 {
    margin: 0.8em 0 0.8em;
    font-size: 1.1em;
    font-weight: 600;
  }
  blockquote {
    padding: 0 1em;
    color: #666;
    border-left: 0.25em solid #ccc;
  }
  table {
    width: 100%;
    color: #444654;
    box-sizing: border-box;
    table-layout: fixed;
    th,
    td {
      padding: 6px 13px;
      border: 1px solid rgb(223, 226, 229);
      vertical-align: middle;
      text-align: left;
      word-wrap: break-word;
      word-break: break-word;
    }
    th {
      font-weight: 600;
      background-color: #ebebeb;
    }
  }
  ul,
  ol,
  li {
    line-height: 20px;
  }
  li {
    list-style: inherit;
    margin: 1em 0;
  }
  ul {
    padding-left: 20px;
  }
  h1,
  h2,
  h3,
  h4 {
    .anchor {
      display: none;
    }
  }
}
pre {
  margin: 0.8em 0;
  font-size: 12px;
}
code {
  font-family: monaco;
  line-height: 1.4;
  color: rgb(199, 37, 78);
  background: rgb(249, 242, 244);
  padding: 2px 4px;
  box-sizing: border-box;
  font-size: 0.93em;
}
strong {
  margin: 1em 0 1em;
  font-weight: bold;
}
a {
  text-decoration: none;
  color: rgb(0, 154, 97);
}
</style>
